import { doLoginApi } from '@/api/userApi'
export default {
  namespaced: true,
  state: {
    userinfo: {
      id: 0,
      token: '',
      avatar: '',
      name: ''
    }
  },
  mutations: {
    setUserInfo(state, payload) {
      state.userinfo = payload
    },
    logout(state, payload) {
      state.userinfo = {
        id: 0,
        token: '',
        avatar: '',
        name: ''
      }
    }
  },
  actions: {
    async loginAction({ commit }, payload) {
      let ret = await doLoginApi(payload)
      if (ret.code === 0) {
        commit('setUserInfo', ret.data)
      }
      return ret.code
    }
  }
}
